<html>
<head><meta charset="utf-8"><title>borrow checking for struct fields · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrow.20checking.20for.20struct.20fields.html">borrow checking for struct fields</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165479878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrow%20checking%20for%20struct%20fields/near/165479878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andrey Rublev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrow.20checking.20for.20struct.20fields.html#165479878">(May 12 2019 at 20:24)</a>:</h4>
<p>Is it possible, maybe in future, to have distinct borrow checking for structure fields, not for entire struct ? In this example <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9c68eb5099baf17c943fadd9d8ca6cb1" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9c68eb5099baf17c943fadd9d8ca6cb1">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=9c68eb5099baf17c943fadd9d8ca6cb1</a> compiler complains because there are mutable and immutable borrows, but in fact there is immutable borrow for self.string and only "state" field  is changed in "mutate" method. Error is easily can be avoided if I move immutable borrowing of self.string inside "mutate" method, but sometimes this approach may not be convenient.</p>



<a name="165550890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/borrow%20checking%20for%20struct%20fields/near/165550890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/borrow.20checking.20for.20struct.20fields.html#165550890">(May 13 2019 at 17:43)</a>:</h4>
<p>it's possible yes, but it will require changes to the language.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>